package com.sxhuangjiang.litadmin.common;

import lombok.Data;

import java.io.Serializable;

/**
 * ajax返回统一数据格式对象。
 * 由于前端使用layui，在字段设计上使用了layui能接受的默认格式。
 * @author huang
 * @version V1.0
 * @date 2019-11-08 14:49
 */
@Data
public class Res<T> implements Serializable {
    private static final long serialVersionUID = 95954497922738429L;
    private Integer code ;
    private String msg;
    private Long count;
    private T data;

    public static <T> Res<T> ok(T data){
        return new Res<T>(0,null,0L,data);
    }
    public static <T> Res<T> err(T data){
        return new Res<T>(-1,null,0L,data);
    }

    public Res<T> page(Long count,T data){
        return new Res<>(0,null,count,data);
    }

    public Res(Integer code, String msg, Long count, T data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }
}
